package com.open.capacity.notice.controller;

import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.open.capacity.common.dto.ResponseEntity;
import com.open.capacity.common.validator.UpdateGroup;
import com.open.capacity.notice.dmo.MessageTemplate;
import com.open.capacity.notice.dto.MessageTemplateDto;
import com.open.capacity.notice.service.MessageTemplateService;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 * 
 * @since 2024-05-06
 */
@RestController
@SuppressWarnings("all")
@RequiredArgsConstructor
@RequestMapping("/messageTemplate")
public class MessageTemplateController {

	private final MessageTemplateService messageTemplateService;

	/**
	 * 分页列表查询
	 *
	 * @param messageTemplate
	 * @param page
	 * @return
	 */
	@ApiOperation(value = "消息模板管理-分页列表查询", notes = "消息模板管理-分页列表查询")
	@GetMapping(value = "/list")
	public ResponseEntity queryPageList(MessageTemplate messageTemplate, Page page) {
		return messageTemplateService.queryPageList(messageTemplate, page);
	}

	/**
	 * 添加
	 *
	 * @param messageTemplateDto
	 * @return
	 */
	@PostMapping(value = "/add")
	@ApiOperation(value = "消息模板管理-添加", notes = "消息模板管理-添加")
	public ResponseEntity<MessageTemplate> add(@Valid @RequestBody MessageTemplateDto messageTemplateDto) {
		return messageTemplateService.add(messageTemplateDto);
	}

	/**
	 * 编辑
	 *
	 * @param messageTemplateDto
	 * @return
	 */
	@ApiOperation(value = "消息模板管理-编辑", notes = "消息模板管理-编辑")
	@PostMapping(value = "/edit")
	public ResponseEntity<Boolean> edit(@Validated({ UpdateGroup.class }) @RequestBody MessageTemplateDto messageTemplateDto) {
		return messageTemplateService.edit(messageTemplateDto);
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "消息模板管理-通过id查询", notes = "消息模板管理-通过id查询")
	@GetMapping(value = "/query-by-id")
	public ResponseEntity queryById(@RequestParam(name = "id") String id) {
		return messageTemplateService.queryById(id);
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "消息模板管理-通过id删除", notes = "消息模板管理-通过id删除")
	@PostMapping(value = "/delete")
	public ResponseEntity<Boolean> delete(@RequestParam(name = "id") String id) {
		return messageTemplateService.delete(id);
	}
}
